package com.blb.service.impl;

import com.blb.mapper.ColumnManagementDao;
import com.blb.pojo.BranchCompany;
import com.blb.pojo.ColumnManagement;
import com.blb.pojo.PageEntity;
import com.blb.service.ColumnManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Service
public class ColumnManagementServiceImpl implements ColumnManagementService {

    @Autowired
    private ColumnManagementDao columnManagementDao;
    @Autowired
    private RedisTemplate redisTemplate;


    @Override
    public List<ColumnManagement> findAllOneColumn() {
        String key="columnManagements";
        ValueOperations<String,List<ColumnManagement>> operations = redisTemplate.opsForValue();
        Boolean hasKey = redisTemplate.hasKey(key);
        if (hasKey){
            System.out.println("通过redis获取数据");
            return operations.get(key);
        }else {
            System.out.println("通过数据库获取数据");
            List<ColumnManagement> columnManagements = columnManagementDao.selectAllOneColumn();
            operations.set(key,columnManagements,1, TimeUnit.MINUTES);
            return columnManagements;
        }
    }
}
